// (C) Copyright 2009, 2010 Communications Programming, Inc.
/***************************************************************************************************************
*  Name: writeBytesI2C1
*
*  Description: Master-writes a sequence of bytes to an I2C device #1, waiting for idle, and 
*  returning status.  A device start is issued before the writes, and a stop after.
*
*  Calling Parameters:
*  
*  int writeBytesI2C1( unsigned char *buf, 	// buffer of data to write
*				 	   unsigned char len );	// number of bytes in buffer to write							
*
*  Returns:    1 = byte not ack'd by slave device
*              0 = success
*
*  Revision History:
*  Date    Who  Comments
*  ------  ---  -----------------------------------------------------------------------------------------
*  091213  RLP	Created.
*
***************************************************************************************************************/

#include "userLib.h"

int writeBytesI2C1( unsigned char *buf, 	// buffer of data to write
			 	   unsigned char len )		// number of bytes in buffer to write							
{
	int i = 0;

	StartI2C();		// Start device
	IdleI2C();		// Wait to complete
	
	for( i = 0; i < len; ++i)
	{
		WriteI2C( buf[i] );			// Write a data byte
		IdleI2C();					// Wait to complete
//		if( I2CSTATbits.ACKSTAT )
//			return(1);
	}

	StopI2C();
	IdleI2C();			//Wait to complete
	return(0);
}
